package StackAndQueue;

import java.util.ArrayDeque;

public class MyStack225 {
    public static void main(String[] args) {
        ArrayDeque<Integer> deque = new ArrayDeque<>();
        deque.push(1);
        deque.push(2);
        deque.push(3);
        System.out.println(deque.pop());
    }

    ArrayDeque<Integer> queue1;
    ArrayDeque<Integer> queue2;
    public MyStack225() {
        queue1 = new ArrayDeque<>();
        queue2 = new ArrayDeque<>();
    }

    public void push(int x) {
        queue1.add(x);
        while(!queue2.isEmpty()){
            queue1.add(queue2.pop());
        }
        ArrayDeque<Integer> queueTemp;
        queueTemp = queue1;
        queue1 = queue2;
        queue2 = queueTemp;
    }

    public int pop() {
        return queue2.poll();
    }

    public int top() {
        return queue2.peek();
    }

    public boolean empty() {
        return queue2.isEmpty();
    }
}
